home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / HardwareContext-m68k.h < prev    next >
C/C++ Source or Header  |  1990-07-09  |  3KB  |  113 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. // 
  3. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  4. // Copyright (C) 1989 University of Colorado, Boulder, Colorado
  5. // Copyright (C) 1990 University of Colorado, Boulder, Colorado
  6. //
  7. // written by Dirk Grunwald (grunwald@foobar.colorado.edu)
  8. //
  9. //
  10. //    Motorola 68000, 68010, 68020 Context Switching
  11. //
  12. #ifndef    HardwareContext_h
  13. #define    HardwareContext_h
  14. #pragma once
  15.  
  16. #include <stream.h>
  17. #include <assert.h>
  18. #include <AwesimeConfig.h>
  19.  
  20. extern const long MagicStackMarker;
  21.  
  22. typedef void (*voidFuncP)();
  23.  
  24. class CpuMultiplexor;
  25. class SingleCpuMux;
  26. class MultiCpuMux;
  27. class SimulationMultiplexor;
  28.  
  29. typedef long HardwareContextQuad;
  30.  
  31. //
  32. //    Although the 68881 only has 8 registers, they store 12 bytes each.
  33. //
  34. static const int HardwareContextFloatQuads
  35.     = (6 * 12) / sizeof(HardwareContextQuad);
  36.  
  37. class HardwareContext {
  38.  
  39.     void** stackBase;    // bottom of stack
  40.     void** stackEnd;    // maximum depth of stack? (actually, a MIN value)
  41.     unsigned stackMax;    // maximum depth of stack? (actually, a MIN value)
  42.     unsigned stackSize;    // stack size in units of void*
  43.     void **stackMallocAt;
  44.     long *stackCheck;    // point to MagicStackMarker to check for corruption
  45.     unsigned checkStackLimits;
  46.     
  47.     friend class Thread;
  48.     friend class CpuMultiplexor;
  49.     friend class SingleCpuMux;
  50.     friend class MultiCpuMux;
  51.     friend class SimulationMultiplexor;
  52.     
  53.     //
  54.     //    Accessed by friend classes only
  55.     //
  56.     void switchContext(HardwareContext *to);
  57.     void magicSwitchTo(HardwareContext *to);
  58.     void **getSp();
  59.     
  60.     void **mallocAt();
  61.     void buildReturnFrame(void * returnThis, voidFuncP returnAddress);
  62.     void stackOverflow();
  63.     
  64.     //
  65.     // never allocated by anything other than friend classes
  66.     //
  67.     HardwareContext(int checked, unsigned stackSize);
  68.     void reclaimStack();
  69.     
  70. public:
  71.     HardwareContext();
  72.     
  73.     long maxStackDepth();
  74.     void checkStack(int overage = 0);
  75.     void classPrintOn(ostream& strm);
  76. };
  77.  
  78. inline
  79. HardwareContext::HardwareContext()
  80. {
  81.     int NotReached = 0;
  82.     assert( NotReached );
  83. }
  84.  
  85. inline ostream&
  86. operator<<(ostream& strm, HardwareContext& ob)
  87. {
  88.     ob.classPrintOn(strm);
  89.     return strm;
  90. }
  91.  
  92. inline void **
  93. HardwareContext::getSp()
  94. {
  95.     void **foo;
  96.     asm volatile ("movel sp,%0" : "=g" (foo));
  97.     return( foo );
  98. }
  99.  
  100. inline void
  101. HardwareContext::checkStack(int overage)
  102. {
  103.     unsigned depth = stackBase - getSp() + overage;
  104.     if (stackMax < depth) {
  105.     stackMax = depth;
  106.     }
  107.     if ( stackMax >= stackSize || *stackCheck != MagicStackMarker ) {
  108.     stackOverflow();
  109.     }
  110. }
  111.  
  112. #endif    HardwareContext_h
  113.